package org.genuflex.utils
{
	import mx.formatters.CurrencyFormatter;
	import mx.formatters.NumberFormatter;
	import mx.formatters.DateFormatter;
	import mx.managers.ISystemManager;
	
	[Mixin]
	public class GenuflexDataFormatter {
      	
		/* Formatters */	  
		public static var currencyFormatter : CurrencyFormatter;
		public static var numberFormatter : NumberFormatter;
		public static var dateFormatter : DateFormatter;
		public static var timeFormatter : DateFormatter;
		      	
		public static function init(systemManager:ISystemManager) : void {
	       	currencyFormatter = getCurrencyFormatter();
	       	numberFormatter = getNumberFormatter();	       	
			dateFormatter = getDateFormatter();		
			timeFormatter = getTimeFormatter();	
      	}		      	

	    private static function getCurrencyFormatter() : CurrencyFormatter
	    {
	       var formatter:CurrencyFormatter = new CurrencyFormatter();
	       formatter.currencySymbol = "$";
	       formatter.precision = 2;

	       return formatter;
	    }  

	    private static function getNumberFormatter() : NumberFormatter
	    {
	       var formatter:NumberFormatter = new NumberFormatter();
	       formatter.precision = 2;	         
	       formatter.useThousandsSeparator = false; 
	       return formatter;
	    }  	    

	    private static function getDateFormatter() : DateFormatter
	    {
	       var formatter:DateFormatter = new DateFormatter();
	       formatter.formatString = "MM/DD/YY";

	       return formatter;
	    }

	    private static function getTimeFormatter() : DateFormatter {
	    	var formatter:DateFormatter = new DateFormatter();
	    	formatter.formatString = "L:NN A";
	    	return formatter;
	    }   

	    public static function formatDate(datetime : Date) : String {
	    	return dateFormatter.format(datetime);
	    }	    	            	
	    public static function formatDateTime(datetime : Date) : String {
	    	return dateFormatter.format(datetime) + " "  + timeFormatter.format(datetime);
	    }	    	            	
	    public static function formatNumber(number: Number) : String {
	    	numberFormatter.useThousandsSeparator = false;
			return numberFormatter.format(number);
	    }      	
	    public static function formatCurrency(number: Number) : String {
	    	numberFormatter.useThousandsSeparator = true;	    	
			return "$" + numberFormatter.format(number);
	    }    

   		public static function formatBooleanToYesNo(value : Boolean) : String {	    	
			return value ? 'Yes' : 'No';
	    }   	      	
	}
}